<?php
/**
 * Created by PhpStorm.
 * User: Egg
 * Date: 2018/3/27
 * Time: 16:19
 */

namespace Admin\Controller;


use Admin\Model\MenuLogic;
use Think\Auth;
use Think\Controller;

class AuthController extends Controller
{
    protected $auth_check_status = true;

    public function _initialize()
    {
        $uid = $this->get_user_id();
        $menu = new MenuLogic();
        $this->assign('menus', $menu->get_menus($uid));
        $auth = new Auth();
        if ($this->get_auth_status() && !$auth->check(MODULE_NAME . '/' . ACTION_NAME, $uid)) {
            $this->display('./no-auth');
            exit;
        }
    }

    /*
     * 获取用户id
     */
    public function get_user_id($to_login = 'true')
    {
        if (session('?uid')) {
            return session('uid');
        } else {
            if ($to_login) {
                $this->display('./login');
            } else {
                return '';
            }
        }
    }

    public function get_auth_status()
    {
        return $this->auth_check_status;
    }

    public function set_auth_status($status)
    {
        $this->auth_check_status = $status;
    }

}